package com.controller;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.DiscussjianshenqicaiEntity;
import com.entity.view.DiscussjianshenqicaiView;
import com.service.DiscussjianshenqicaiService;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * 健身器材评论表
 */
@RestController
@RequestMapping("/discussjianshenqicai")
public class DiscussjianshenqicaiController {
    @Autowired
    private DiscussjianshenqicaiService discussjianshenqicaiService;




    


    /**
     * 后端列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,DiscussjianshenqicaiEntity discussjianshenqicai, 
		HttpServletRequest request){

        EntityWrapper<DiscussjianshenqicaiEntity> ew = new EntityWrapper<DiscussjianshenqicaiEntity>();


		PageUtils page = discussjianshenqicaiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discussjianshenqicai), params), params));
        return R.ok().put("data", page);
    }
    
    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,DiscussjianshenqicaiEntity discussjianshenqicai, 
		HttpServletRequest request){
        EntityWrapper<DiscussjianshenqicaiEntity> ew = new EntityWrapper<DiscussjianshenqicaiEntity>();

		PageUtils page = discussjianshenqicaiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discussjianshenqicai), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( DiscussjianshenqicaiEntity discussjianshenqicai){
       	EntityWrapper<DiscussjianshenqicaiEntity> ew = new EntityWrapper<DiscussjianshenqicaiEntity>();
      	ew.allEq(MPUtil.allEQMapPre( discussjianshenqicai, "discussjianshenqicai")); 
        return R.ok().put("data", discussjianshenqicaiService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(DiscussjianshenqicaiEntity discussjianshenqicai){
        EntityWrapper< DiscussjianshenqicaiEntity> ew = new EntityWrapper< DiscussjianshenqicaiEntity>();
 		ew.allEq(MPUtil.allEQMapPre( discussjianshenqicai, "discussjianshenqicai")); 
		DiscussjianshenqicaiView discussjianshenqicaiView =  discussjianshenqicaiService.selectView(ew);
		return R.ok("查询健身器材评论表成功").put("data", discussjianshenqicaiView);
    }
	
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        DiscussjianshenqicaiEntity discussjianshenqicai = discussjianshenqicaiService.selectById(id);
        return R.ok().put("data", discussjianshenqicai);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        DiscussjianshenqicaiEntity discussjianshenqicai = discussjianshenqicaiService.selectById(id);
        return R.ok().put("data", discussjianshenqicai);
    }
    



    /**
     * 后端保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DiscussjianshenqicaiEntity discussjianshenqicai, HttpServletRequest request){
    	discussjianshenqicai.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
    	//ValidatorUtils.validateEntity(discussjianshenqicai);

        discussjianshenqicaiService.insert(discussjianshenqicai);
        return R.ok();
    }
    
    /**
     * 前端保存
     */
    @RequestMapping("/add")
    public R add(@RequestBody DiscussjianshenqicaiEntity discussjianshenqicai, HttpServletRequest request){
    	discussjianshenqicai.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
    	//ValidatorUtils.validateEntity(discussjianshenqicai);

        discussjianshenqicaiService.insert(discussjianshenqicai);
        return R.ok();
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DiscussjianshenqicaiEntity discussjianshenqicai, HttpServletRequest request){
        //ValidatorUtils.validateEntity(discussjianshenqicai);
        discussjianshenqicaiService.updateById(discussjianshenqicai);//全部更新
        return R.ok();
    }

    
    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        discussjianshenqicaiService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
    
	









}
